package com.starblink.product.detail.dialog

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.starblink.android.basic.base.BaseViewModel
import com.starblink.android.basic.network.base.SkGqlClient
import com.starblink.rocketreserver.FetchSelectedProductReviewQuery
import kotlinx.coroutines.launch

class StoreReviewVM : BaseViewModel() {
    var mList: MutableLiveData<MutableList<Any>> =
        MutableLiveData()

    /**
     * 获取店铺详情
     */
    fun loadList(id: String) {
        viewModelScope.launch {
            val response = SkGqlClient.skQuery(
                FetchSelectedProductReviewQuery(
                    id,
//                    countryCode = Optional.present(UserDataCenter.getLocalCountryCode())
                )
            )
            Log.e("StoreReviewVM","======$id====${response?.data?.fetchSelectedProductReview}")
            if (response?.data != null && response.data!!.fetchSelectedProductReview != null) {
                var postList = response.data!!.fetchSelectedProductReview
                var list =
                    mutableListOf<FetchSelectedProductReviewQuery.FetchSelectedProductReview>()
                postList!!.forEach { e ->
                    e?.let { list.add(it) }
                }
                mList.value?.addAll(list)
                mList.value?.add("more")
                mList.value = mList.value
            }
        }
    }
}